package com.oocl.ita.handler;

import java.awt.Point;

import com.oocl.ita.qqclientt.QQClient;
import com.oocl.ita.sakura.protocol.Protocol;
import com.oocl.ita.ui.ChatFrame;

public class ShakeHandler implements IHandler {
	/*
	 * (non-Javadoc)
	 * @see com.oocl.ita.handler.IHandler#handle(com.oocl.ita.sakura.protocol.Protocol)
	 * 
	 * 其实接口用处很多
	 * 接口中的函数的参数扔可以是接口
	 */

	@Override
	public void handle(Protocol protocol) {		
		/*
		 * 处理Shake Protocol 
		 * 
		 */
		System.out.println("ShakeHandler " + QQClient.getClient() + protocol);
		
		// 处理震动
		System.out.println("ShakeHandler : "  + QQClient.getClient() + "Shaking...");
		shake(QQClient.getChatFrame());
	}
	
	public void shake(ChatFrame chatFrame){
		int x = chatFrame.getLocation().x;
		int y = chatFrame.getLocation().y;
		
		for(int i = 0; i < 10; i++){
			try{
				Point endPoint = new Point(x + 10, y + 10);
				chatFrame.setLocation(endPoint);
				Thread.sleep(100);
				endPoint = new Point(x - 10, y - 10);
				chatFrame.setLocation(endPoint);
				Thread.sleep(100);
			}
			catch(InterruptedException e){
				e.printStackTrace();
			}
		}
	}
}
